﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HomeCare.Model;

namespace HomeCare.View
{
    public partial class RelMedicos : Form
    {
        public RelMedicos()
        {
            InitializeComponent();
        }

        private void btnConsultar_Click(object sender, EventArgs e)
        {
            PessoaDados dados = new PessoaDados();
            Pessoa pessoa = new Pessoa();
            pessoa.nome = txtNome.Text;
            if (cmbSexo.SelectedIndex != -1)
                pessoa.sexo = Convert.ToChar(cmbSexo.SelectedText.Substring(0, 1));
            else
                pessoa.sexo = null;
            pessoa.rg = txtRG.Text;
            pessoa.cpf = txtCPF.Text;
            DataSet ds = dados.GetRelatorioMedico(pessoa);
            lblTotal.Text = ds.Tables[0].Rows.Count.ToString();
            dgvMedicos.ReadOnly = true;

            if (ds.Tables[0].Rows.Count > 0)
            {
                int row = ds.Tables[0].Rows.Count - 1;
                for (int r = 0; r <= row; r++)
                {
                    dgvMedicos.Rows.Add();

                    dgvMedicos.Rows[r].Cells[0].Value = ds.Tables[0].Rows[r].ItemArray[0].ToString();
                    dgvMedicos.Rows[r].Cells[1].Value = ds.Tables[0].Rows[r].ItemArray[1].ToString().ToUpper();
                    DateTime dataInicial = (DateTime)ds.Tables[0].Rows[r].ItemArray[2];
                    dgvMedicos.Rows[r].Cells[2].Value = dataInicial.ToString("dd/MM/yy HH:MM");
                    dgvMedicos.Rows[r].Cells[3].Value = ds.Tables[0].Rows[r].ItemArray[3].ToString();
                    dgvMedicos.Rows[r].Cells[4].Value = ds.Tables[0].Rows[r].ItemArray[4].ToString();
                    dgvMedicos.Rows[r].Cells[5].Value = ds.Tables[0].Rows[r].ItemArray[5].ToString();
                }
            }
            else
            {
                MessageBox.Show("Nenhum registro encontrado.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }
    }
}
